<?php


namespace App\Common;


use Illuminate\Http\Request;

class RedisKey
{
    // 获取缓存key完整前缀
    public static function getCacheKeyPrefix(Request $request)
    {
        $cacheKeyPrefixParts[] = config('cache.prefix_api');
        $cacheKeyPrefixParts[] = $request->method();
        $cacheKeyPrefixParts[] = md5($request->url());
        $cacheKeyPrefix        = implode("_", $cacheKeyPrefixParts);
        return $cacheKeyPrefix;
    }

    // 获取缓存key
    public static function getCacheKey(Request $request)
    {
        $cacheKeyPrefix = self::getCacheKeyPrefix($request);
        $qs             = $request->getQueryString();
        $cacheKey       = $cacheKeyPrefix . "_" . md5($qs);
        return $cacheKey;
    }
}
